<template>
  <el-dialog :visible.sync="dialogVisible" title="验证" :before-close="handleClose" width="600px">
    <el-form ref="formRef" :model="formData" label-width="120px" :rules="rules" @submit.native.prevent>
      <el-form-item :label="$t('halykDingDanHao')+'：'">
        {{ formData.haOrderCode }}
      </el-form-item>
      <el-form-item label="验证码：" prop="otpCode">
        <el-input v-model="formData.otpCode" placeholder="请输入验证码"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button size="small" type="primary" :loading="loading" @click="submitForm">{{ $t('confirm') }}</el-button>
      <el-button size="small" @click="handleClose">{{ $t('cancel') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { otpCodeCheckApi } from '@/api/halykOrder'
export default {
  data() {
    return {
      loading: false,
      dialogVisible:false,
      formData: {
        haOrderCode:'',
        orderId: null,
        otpCode:''
      },
      rules: {
        otpCode: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
      }
    }
  },
  mounted() {},
  methods: {
    show(row) {
      this.formData.orderId = row.id
      this.formData.haOrderCode = row.haOrderCode
      this.dialogVisible = true
    },
    submitForm() {
      this.$refs['formRef'].validate((valid) => {
        if (valid) {
          this.loading = true
          otpCodeCheckApi(this.formData).then(res=>{
            this.$message.success(this.$t('caoZuoChengGong'))
            this.$emit('updata')
            this.loading = false
            this.handleClose()
          }).catch(() => {
              this.loading = false
            })
        } else {
          return false;
        }
      });
    },
    handleClose() {
      this.$refs['formRef'].resetFields();
      this.dialogVisible = false
    }
  }
}
</script>

<style scoped lang="scss">
</style>
